package com.centersoft.flowable.db.task.convert;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.centersoft.flowable.core.model.FlowAssigneeModel;
import com.centersoft.flowable.db.task.entity.FlowAssigneeEntity;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

public class FlowAssigneeConvert {

    public static FlowAssigneeModel toModel(FlowAssigneeEntity entity) {
        FlowAssigneeModel model = new FlowAssigneeModel();
        model.setId(entity.getId());
        model.setType(entity.getType());
        model.setSort(entity.getSort());
        model.setOperationType(entity.getOperationType());
        if (StringUtils.isNotBlank(entity.getConditions())) {
            model.setConditions((JSONObject) JSON.parse(entity.getConditions()));
        }
        if (StringUtils.isNotBlank(entity.getValue())) {
            model.setValues(Arrays.asList(entity.getValue().split(",")));
        }
        return model;
    }
}
